package com.xinqi.modules.exam.analyze.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.analyze.dto.req.CourseExamAnalyzeStudentScoreQuestDTO;
import com.xinqi.modules.exam.analyze.dto.rsp.CourseExamAnalyzeStudentScoreDTO;
import com.xinqi.modules.exam.analyze.dto.rsp.CourseExamPaperAnalyzeResultDTO;
import com.xinqi.modules.exam.analyze.service.CourseExamPaperAnalyzeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程测评分析APP控制层
 *
 * @author: linkai
 * @date: 2023/07/02
 */
@Tag(name = "App-课程测评分析", description = "课程测评分析App接口")
@RestController
@RequestMapping("/app/exam-paper")
@RequiredArgsConstructor
public class CourseExamPaperAnalyzeAppController {
    private final CourseExamPaperAnalyzeService courseExamPaperAnalyzeService;

    /**
     * 课程测评分析-详情
     */
    @Operation(summary = "课程测评分析-详情")
    @GetMapping("/{exam-id}/analyze/detail")
    public R<CourseExamPaperAnalyzeResultDTO> findById(
        @Parameter(description = "测评ID", example = "100001") @PathVariable("exam-id") Long examId
    ) {
        CourseExamPaperAnalyzeResultDTO dto = courseExamPaperAnalyzeService.findByExamId(examId);
        return R.data(dto);
    }

    /**
     * 生成课程测评分
     */
    @Operation(summary = "生成课程测评分析")
    @PostMapping("/{exam-id}/analyze/generate")
    public R<Boolean> generate(
        @Parameter(description = "测评ID", example = "100001") @PathVariable("exam-id") Long examId
    ) {
        return R.data(courseExamPaperAnalyzeService.generate(examId));
    }

    /**
     * 查询学生等分情况
     */
    @Operation(summary = "查询学生等分情况")
    @GetMapping("/{exam-id}/analyze/student-score")
    public R<PageInfo<CourseExamAnalyzeStudentScoreDTO>> studentScore(
        @Parameter(description = "测评ID", example = "100001") @PathVariable("exam-id") Long examId,
        @ParameterObject CourseExamAnalyzeStudentScoreQuestDTO questDTO
    ) {
        questDTO.setExamId(examId);
        return R.data(courseExamPaperAnalyzeService.findStudentScore(questDTO));
    }

}
